 <?php


/**
 * @author yaya
 * 
 */
class ReceiveClusterIM {
	private $message = ""; //返回消息
	private $nowCommd; //当前命令
	private $level = 0; //个人好感度等级
	private $clusterLevel = 0; //当前群好感度等级
	private $adminLevel = 0; // 权限级别 0普通   1管理    2主人
	private $auth = null;
	private $blacklist;
	private $flag = true;
	private $cm;
	private $cp;
	private $filter;
	private $whitelist;
	function ReceiveClusterIM() {
		//初始化一些参数;
		$p = "/(^@索妮娅酱)|(^@索妮娅)/";
		$_POST[Message] =  preg_replace($p,'',trim($_POST[Message]));
		Favorable :: getClusterFav();
		$this->init();

	}

	private function init() {
		$this->blacklist = new Blacklist();
		$this->whitelist = new Whitelist();
		$this->cp = new ClusterParam();
		$this->cm = new ClusterManager();
		$this->filter = new Filter();
		$this->filter->cp = $this->cp;
		//myEcho(Favorable::getFavLevByFv());
		//初始化权限
		//if("261589289"==$_POST[Sender]) {
			//$fav = (int)Favorable::getFavLevByFv();
			//if($fav<=7) {
			//	$this->exitCluster($_POST[ClusterNum]);
				
					//echo $fav;
				//}
		//}
		$this->auth = $this->blacklist->auth;

		if (!$this->whitelist->isInWhitelist() && $this->auth->adminLevel < 5 && $this->cm->filter == 1) {
			$this->filter->filterCheck();
			$this->message = $this->filter->message;
			if ($this->message != "") {
				$this->flag = false;
				return;
			}
		}

		//黑名单统一忽略
		if ($this->blacklist->isInBlacklist()) {
			$this->flag = false;
			return;
		}
		
		$this->antiBrush();
		$this->aToBcluster();
		/*
		* 若当前还在交互模式下
		*/
		if ($this->flag && isset ($_SESSION['QUN_MODE'])) {
			$this->execMode(null);
			$this->flag = false;
			return;
		}
		if ($this->flag) {

			//ac视频信息检测
			if ($this->cm->acvideo == 1) {
				$this->message = acVedio($this->cp);
				if ($this->message != "") {
					$this->flag = false;
				}
			}

			//备份数据
			if ($this->cm->bak == 1) {
				$this->bakMessage();
			}

		}

		//

	}
	public function run() {

		//echo "今天是索妮娅1周岁的生日，不来祝贺索妮娅酱的都关进小黑屋、、[Image{B24BDC42-9BE9-78F9-C893-F5178990D5AA}.gif]" ;
		//return ;
		if (!$this->flag) {
			return;
		}
		//解析消息 @XX 被视为命令
		preg_match('/^@(\S+)\s*(.*)$/is', trim($_POST[Message]), $m);

		if (null != $m) {
			if($_GET[flag]==1) {
				return;
			}
			$nowCommd = $m[1];
			$commdMess = DB :: GetTableRow("td_qun_commd", array (
				"key" => $nowCommd
			));
			myEcho("\n执行命令：{$nowCommd}\n");
			if (null != $commdMess) { //是命令则执行
				if ($this->auth->adminLevel < 5 && $this->cm->open == 0 && $commdMess['key'] != "open") { //
					$this->message = $this->cp->getParamValue('SERVICE_OPEN_MESS');
					return;
				}
				if(!isset($_SESSION['is_update'])) {
					$_SESSION['is_update'] = 1 ;
					Favorable::addUserInfo();
				}
				if($_SESSION['is_update']<20) {
					Favorable::updateUserInfo(1);
				}
				$execNam = $commdMess['value'];
				
				$_SESSION[$execNam]['num'] = $_SESSION[$execNam]['num']?($_SESSION[$execNam]['num']+1):1;
				if($_SESSION[$execNam]['num']>=$commdMess['exec_times']){
					if(time()<$_SESSION[$execNam]['time']+$commdMess['space_time'] && $this->auth->adminLevel<4) {
						$this->message = "你说的太快了,请稍等一会儿~";
						return ;
					}
				}
				$_SESSION[$execNam]['time'] = time();
				//重新初始化权限等级
				if ($this->auth->adminLevel < 5 && $commdMess[isadmin] > 0)
					$this->auth = new Authority(true);

				
				if ($this->auth->adminLevel < $commdMess[ismanager]) { //内部命令 不开放
					$this->message = "非公开命令0(>_<)0~~";
					return;
				} else {

					if ($this->auth->adminLevel < 4 && $this->auth->isClusterAdmin < $commdMess[isadmin]) { //群管理 或者机器人 管理等级大于或者等于4级的
						$this->message = "权限不足0(>_<)0~~";
						return;
					}
					if ($this->auth->adminLevel < 1 && $this->auth->clusterLevel < $commdMess[favlevel]) { //机器人管理等级大于或者等于1的
						$this->message = "好感度等级不足,查看当前群好感度等级 @好感度  ";
						return;
					}

					//增加好感度
					//Favorable :: clusterFavReward($commdMess[reward]);
					//Favorable :: updateUserInfo($commdMess[reward]);
					/*
					 * 是否为交互模式命令
					 */
					if ($commdMess[is_mode] == 1) {
						$this->execMode($execNam);
						return;
					}
					if($_POST[Sender]=="80000000") {
						$this->message = "请不要匿名执行~~=_=~~";
						return;
					}
					if ($commdMess[isclass] == 0) { //  类函数处理命令
						$this-> $execNam ();
						myEcho("\n执行函数：{$execNam}\n");

					} else
						if ($commdMess[isclass] == 2) { //类处理命令
							$modelfile = ROOT_PATH . "Lib/Mode/{$execNam}.class.php";
							myEcho("\n执行模块：{$execNam}\n");
							if (file_exists($modelfile)) {
								require_once ("{$modelfile}");
								$exec = new $execNam;
								$exec->run();
								$this->message = $exec->message;
							}
						} else
							if ($commdMess[isclass] == 1) { //公共函数处理命令
								$this->message = $execNam ();
								myEcho("\n执行函数：{$execNam}\n");
							}
				}

			} else { //不是命令则看是否为@XX 群员功能
				$modelfile = ROOT_PATH . "Lib/Mode/Mention.class.php";
				require_once ("{$modelfile}");
				$M = new Mention();
				$this->message = $M->doMention($nowCommd);

			}

		} else {

			if ($this->auth->adminLevel < 1 && $this->cm->open == 0) {
				return;
			}
			//Favorable :: clusterFavorAdd(1);
			$startTime = microtime(TRUE);
			require_once (ROOT_PATH . "Lib/Mode/Study.class.php");
			$study = new Study();
			
			$study->getStudyAnswer();
			$this->message = $study->message;
			
			$endTime = microtime(TRUE);
			myEcho("\n词库查找时间：" . ($endTime - $startTime) . "\n");
		}

	}

	/**
	 * 群统计报告 @report
	 */
	private function getReport() {
		$clusterParam = $this->cp;
		if ($this->cm->bak == 0) {
			$this->message = "本群还没有开启消息记录备份,请管理员 @bak 开启、";
			return;
		}
		$p = '/@report[^0-9]*(20[0-9][0-9]-[0-9][0-9]-[0-9][0-9])*[^0-9]*(20[0-9][0-9]-[0-9][0-9]-[0-9][0-9])*/si'; //([^0-9]*([0-9]*))|
		preg_match($p, $_POST[Message], $m);
		$qq = $_POST[ClusterNum];
		$part = (int)substr($qq,-2,2);
		if ($m[1]) {
			$date0 = $m[1];
			if ($m[2]) {
				$date1 = $m[2];
			} else {
				$date1 = $date0;
			}
		} else {
			$date0 = date("Y-m-d", time() + 8 * 3600);
			$date1 = date("Y-m-d 23:59:59", time() + 8 * 3600);
		}

		if (!$m[2])
			$where = ' part = '.$part.' and ClusterNum=\'' . $qq . '\'  and DATE_FORMAT(SendTime,\'%Y-%m-%d\') = \'' . $date0 . '\' ';
		if ($m[1] && $m[2])
			$where = ' part = '.$part.' and ClusterNum=\'' . $qq . '\' and  DATE_FORMAT(SendTime,\'%Y-%m-%d\') >= \'' . $date0 . '\'  and SendTime <=\'' . $date1 . '\'';

		$sql = 'select count(*) A from td_message_partition where ' . $where;
		//echo $sql;
		$ret = DB :: GetQueryResult($sql, false);
		$all_count = $ret[0][a];
		//		if($all_count <= 0) {
		//			$this->message = "- -、、好难统计啊~~~_~~~" ;
		//			return ;
		//		}
		$sql2 = 'select NICK,Sender,count(Sender) c  from td_message_partition where ' . $where . ' group by Sender order by c';
		$ret2 = DB :: GetQueryResult($sql2, false);
		$all_mb = count($ret2);
		//		echo $sql2;
		$s = "";
		if ($m[1]) {
			if ($m[2])
				$list = "群统计报告：\n从{$m[1]}到{$m[2]}期间,共有 " . $all_mb . " 人发言,共计 " . $all_count . "条\n详细情况如下所示\n";
			else
				$list = "群统计报告：\n在{$m[1]}这天内,共有 " . $all_mb . " 人发言,共计 " . $all_count . "条\n详细情况如下所示\n";
		} else {
			$s = "今日";
			$list = "群今日报告：\n今天共有 " . $all_mb . " 人发言,共计 " . $all_count . "条\n详细情况如下所示\n";
		};
		$j = $all_mb;
		foreach ($ret2 as $v) {
			if ((($all_mb--) - 10) > 0) {
				continue;
			}
			$list = $list . str_pad($v[nick], 30) . "\t(" . $v[sender] . ")\t{$s}怒刷存在感：" . $v[c] . "次\n";
		}
		$sw = $ret2[count($ret2) - 1];
		if ($m[1])
			$list = $list . "\n恭喜 " . $sw[nick] . " 成为本群" . $clusterParam->getParamValue('REPORT_NUMBER_ONE');
		else
			$list = $list . "\n恭喜 " . $sw[nick] . " 成为今日" . $clusterParam->getParamValue('REPORT_NUMBER_ONE') . "\n并获得成就：" . $clusterParam->getParamValue('REPORT_NUMBER_ONE_MESS');

		$this->message = $list;
	}
	/**
	 * 好感度信息  @好感度
	 */
	public function getFavorMess() {

		$this->message = Favorable :: viewFav();
	}

	/**
	 * 群内公告信息  @公告 内容
	 */
	public function announcement() {
		$p = '/@公告\s+(.*)/is';
		preg_match($p, $_POST[Message], $m);
		$message = $m[1]; //[Image{8B23EDA3-D2F6-EF6C-C6A2-A95CA954B3A5}.gif] "; //[Image{BDD37039-52B0-7ABF-C10A-2087331C88B7}.jpg][Face39.gif] - -半夜守群中~！半夜守群中~！ _(:3」∠)_  _(:3」∠)_
		// global ;
		$ret = DB :: GetQueryResult("select * from td_view_fav order by update_time desc limit 50", false); //
		$i = 0;
		foreach ($ret as $value) {
			if($i==0) 
				$qq = $value[clusternum];
			else
				$qq = $qq . "," . $value[clusternum]; //echo $value;
			$i++;
		}
		$api = new Api('SendClusterMessage');
		$this->message = $api->doApi($qq, $message);
	}

	/**
	 * 链接群 @link <->群号
	 */
	public function linkCluster() {
		$p = '/@link[\s]*(<?)-(>?)([0-9]+)/si';
		preg_match($p, trim($_POST[Message]), $m);
		$qq = $m[3];

		if (!$qq || !(($m[1] && $m[2]) || $this->auth->adminLevel > 0 && ($m[1] || $m[2]))) {

			$this->message = '参数有误，请仔细检查！';
			return;
		}

		if ($this->auth->adminLevel < 1 && $this->auth->getClusterAdmin($qq, $_POST[Sender]) < 1) {
			$this->message = "您还不是群[{$qq}]的管理员,无法连接上";
			return;
		}
		if ($m[1])
			DB :: SaveTableRow('td_a_to_b', array (
				'Parents' => $qq,
				'child' => $_POST[ClusterNum]
			));
		if ($m[2])
			DB :: SaveTableRow('td_a_to_b', array (
				'Parents' => $_POST[ClusterNum],
				'child' => $qq
			));
		if ($m[1] && $m[2]) {
			$api = new Api("SendClusterMessage");
			$api->doApi($qq, "{$post[Nick]}通过索尼娅，链接本群成功~！可以开始会话了！");
			$this->message = "已经和群[" . $this->getClusterName($qq) . "]({$qq})建立链接， 可以开始会话了~！";
		}
		elseif (!$m[1] && $m[2]) {
			$this->message = "已经和群[" . $this->getClusterName($qq) . "]({$qq})建立链接，但本群无法看到对方群信息，对方可看见本群消息";
		} else {
			$this->message = "已经和群[" . $this->getClusterName($qq) . "]({$qq})建立链接，本群可看见对方群信息，但是对方无法看到本群消息";
		}
	}

	private function getClusterName($cluster) {
		$ret = DB :: LimitQuery('td_cluster_favorable', array (
			'condition' => array (
				'ClusterNum' => $cluster
			)
		), false);

		return $ret[0][clustername] == "" ? "未知的群" : $ret[0][clustername];
	}
	private function bakMessage() {
		$_POST[id] = 0;
		$_POST[SendTime] = date("Y-m-d H:i:s", $_POST[SendTime] + 8 * 3600);
		$_part = (int)substr($_POST[ClusterNum],-2,2);
		$message = array (
			'id' => $_POST[id],
			'Copyright' => $_POST[Copyright],
			'Event' => $_POST[Event],
			'ClusterNum' => $_POST[ClusterNum],
			'ClusterName' => $_POST[ClusterName],
			'Sender' => $_POST[Sender],
			'Nick' => $_POST[Nick],
			'part'=> $_part,
			'Message' => $_POST[Message],
			'SendTime' => $_POST[SendTime],
			'Version' => "",
			'RobotQQ' => $_POST[RobotQQ],
			'ApiPort' => $_POST[ApiPort]
		);
		//return ;
		@ DB :: SaveTableRow(MESSAGE_TABLE, $message);
	}

	/**
	 * 防刷
	 */
	private function antiBrush() {
		if (!isset ($_SESSION['message'])) {
			$_SESSION['message'] = $_POST[Message];
			$_SESSION['message_old'] = "";
			$_SESSION['num'] = 1;
			$_SESSION['time'] = time();
			return;
		}

		if ($_SESSION['message'] == $_POST[Message]) {

			$_SESSION['num'] = $_SESSION['num'] + 1;
			$ANTI_BRUSH_NUM = $this->cp->getParamValue('ANTI_BRUSH_NUM');
			if ($_SESSION['num'] >= $ANTI_BRUSH_NUM) {
				if ($_SESSION['num'] <= ($ANTI_BRUSH_NUM +1)) {
					$ANTI_BRUSH_MESS = $this->cp->getParamValue('ANTI_BRUSH_MESS');
					$this->message = $ANTI_BRUSH_MESS;
				}
				$this->flag = false;
			}
		} else {
			$_SESSION['message_old'] = $_SESSION['message'];
			$_SESSION['message'] = $_POST[Message];
			$_SESSION['num'] = 1;
			$_SESSION['time'] = time();

		}
	}

	function getTop10() {
		$p = '/@Top10[\s]*(-a)*[\s]*([0-9]+)*/si';

		preg_match($p, trim($_POST[Message]), $n);
		$order = "desc";
		$limit = "10";

		if ($n[2] && $this->auth->adminLevel > 0) {

			$limit = $n[2];
		}
		$m = "好感度前{$limit}的群如下：\n";
		if ($n[1]) {
			$m = "好感度末尾{$limit}个的群如下：\n";
			$order = "asc";
		}
		$ret = DB :: GetQueryResult("select * from td_view_fav where is_in_cluster=1 order by favorable {$order} limit 0,{$limit} ", false); //

		$i = 1;
		foreach ($ret as $v) {
			$lv = Favorable :: getFavLev($v[clusternum]);
			if($lv[lv]==9)
				$lv[lv] = "⑨";
			if($this->auth->adminLevel>0) {
				$clusternum = $v[clusternum] ;
			} else {
				$clusternum = $v[clusternum]==$_POST[ClusterNum] ?$v[clusternum] :getreClusterNum($v[clusternum]) ;
			}
			
			$m = $m . ($i++) . ".\t" . "Lv" . $lv[lv] . "(" . $v[favorable] . ")  \t" . ($v[clustername] == "" ? "未获取群名字" : $v[clustername]) . "(" . $clusternum. ")\n";
		}
		$this->message = $m;
	}

	private function changeCard() {
		$p = '/@改名[\s]+([0-9]+)*(.*)/si';
		
		preg_match($p, trim($_POST[Message]), $n);
		//return;
		$MemberQQ = $_POST[Sender];
		$mC = "" ;
		if ($n) {
			if($this->auth->adminLevel>=5) {
				if(!$n[1]) {
					$MemberQQ = '1004634672';
				} else {
					$MemberQQ = $n[1];
				}
				$mC = $n[2];
			} else {
				if(!$n[1]) {
					$MemberQQ = $_POST[Sender];
				} else {
					$MemberQQ = $n[1];
				}
				$mC = $n[2];
			}
			//$mC = '..sd是a';
			//echo rawurlencode($mC);
			$url = "Http://127.0.0.1:" . $_POST[ApiPort] . "/Api?id={$_POST[ClusterNum]}&key=261589289&SendType=ChangeClusterMemberCard&utf=1&MemberQQ={$MemberQQ}&CardName=" . rawurlencode($mC);
			$do = new CurlUtil($url);
			$do->init();
			$do->getBody();
			$this->message = "好的0(>_<)0~~";
		} else {
			$this->message = "参数有误,Baka!";
		}
	}

	private function execMode($execCom = null) {
		if (!isset ($_SESSION['QUN_MODE'])) {
			$_SESSION['QUN_MODE'] = $execCom;
			$modelfile = ROOT_PATH . "Lib/Mode/{$execCom}.class.php";
			require_once ("{$modelfile}");
			$do = new $execCom;
			$do->run();
			$this->message = $do->message;
		} else {
			$class = $_SESSION['QUN_MODE'];
			$modelfile = ROOT_PATH . "Lib/Mode/{$class}.class.php";
			require_once ("{$modelfile}");
			$do = new $class;
			$do->run();
			$this->message = $do->message;
		}
	}

	private function enterCluster() {
		$p = '/@([\S]+)\s+(.*)/';
		preg_match($p, trim($_POST[Message]), $m);
		if ($m == "加群") {

		} else
			if ($m[1] == "加好友") {

			} else
				if ($m[1] == "退群") {

				}
	}


	private function altAll() {
		$p = '/@\S+\s*?(.*)/';
		preg_match($p, trim($_POST[Message]), $m);
		if($m[1]) {
			$this->message = "[@:0:我的小伙伴]".$m[1];
		} else {
			$this->message = "[@:0:我的小伙伴] 快出来陪索妮娅玩~";
		}
	}

	private function getHistoryMess() {
		$p = '/@getms[^0-9]+([0-9]+)[^0-9]*([0-9]*)[^0-9]*([0-9]*)/';
		preg_match($p, trim($_POST[Message]), $m);
		$cd_qq = $m[1];
		$sql = "select count(*) A from td_message_partition where  ClusterNum='{$_POST[ClusterNum]}'  and  Sender={$cd_qq}  ";
		$ret = DB :: GetQueryResult($sql, false);
		$all_count = $ret[0][a];
		$all_page = ceil($all_count / 10);
		$page = 0;
		if ($m[2]) {
			if ($m[2] > $all_page)
				$page = $all_page;
			else
				$page = $m[2];
		} else {
			$page = 1;
		}
		$condition = array (
			'ClusterNum' => $_POST[ClusterNum],
			'Sender' => $cd_qq,
			'event' => 'ReceiveClusterIM'
		);

		$options = array (
			'condition' => $condition,
			'offset' => ($page -1) * 10,
			'size' => 10,
			'order' => 'order by sendtime DESC '
		);
		//print_r($options);
		$ret = DB :: LimitQuery('td_message_partition', $options);
		//print_r($ret);
		$l = "  ";
		foreach ($ret as $a) {
			$l = $l . $a[nick] . " 在 " . $a[sendtime] . " 说：\n" . $a[message] . "\n  ";
		}
		if ($all_count > 0) {
			//echo $l;
			echo $l . "\n首页  -> " . "@getms {$cd_qq} 1\n";
			if ($page != 1)
				echo "上一页-> " . "@getms {$cd_qq} " . ($page -1) . "\n";
			if ($page != $all_page)
				echo "下一页-> " . "@getms {$cd_qq} " . ($page +1) . "\n";
			echo "尾页  -> " . "@getms {$cd_qq} {$all_page}";
		}
	}

	private function searchMessage() {
		$p = '/@(\S+)\s+(\S+)/';
    $part = (int)substr($_POST[ClusterNum],-2,2);
		preg_match($p, $_POST[Message], $m);
		$key = trim($m[2]);

//		if ($qq) {
//			$sql = "select * from td_message_partition where  	ClusterNum	={$_POST[ClusterNum]} and Sender='" . $qq . "' and Message like '%" . $key . "%'";
//		} else {
			$sql = "select * from td_message_partition where part = {$part} and ClusterNum={$_POST[ClusterNum]} and Message like '%" . $key . "%'";
//		}
		//echo $sql;
		$ret = DB :: GetQueryResult($sql, false);
		$l = " 有关 “" . $key . "”的记录如下 ：";
		foreach ($ret as $a) {
			$l = $l . $a[nick] . " 在 " . $a[sendtime] . " 说：\n" . $a[message] . "\n  ";
		}
		echo $l;

	}
	
	private function  searchTech() {
		$ret = DB :: GetTableRow("td_study", array (
				"id" => $_SESSION['NOW_MESS_ID'] 
			));
		if($ret) {
			$timeM = "";
			if($ret[start_date]==0  && $ret[start_time]!=0 ){ 
				if($ret[end_date]==0  && $ret[end_time]!=0 ){ 
					$timeM = "每天".substr($ret[start_time],0,2)."点".substr($ret[start_time],2,2)."分".substr($ret[start_time],4,2)."秒" .
					"~".substr($ret[end_time],0,2)."点".substr($ret[end_time],2,2)."分".substr($ret[end_time],4,2)."秒" ; 
				}
			}
			
			if($ret[start_date]!=0  && $ret[start_time]==0 ){ 
				if($ret[end_date]!=0  && $ret[end_time]==0 ){ 
					$timeM = substr($ret[start_date],0,4)."年".substr($ret[start_date],4,2)."月".substr($ret[start_date],6,2)."日".
					"~".substr($ret[end_date],0,4)."年".substr($ret[end_date],4,2)."月".substr($ret[end_date],6,2)."日";
				}
			}
			
			if($timeM =="") {
				$timeM = "任何时间" ;
			}
			
			$clusterName = getClusterNameBynum($ret[clusternum])."({$ret[clusternum]})";
			if($ret[clusternum]!=$_POST[ClusterNum] && $this->auth->adminLevel< 1) {
				$clusterName = getClusterNameBynum($ret[clusternum]);
			}
			
			$this->message = "词条标识：\t".$_SESSION['NOW_MESS_ID'] ."\n".
			"优先级：\t".$ret[priority]."\n".
			"调教人QQ：\t".$ret[qq]."\n".
			"词条所属群：\t".$clusterName."\n".
			"调教时间：\t".$ret[update_time]."\n".
			"有效时间：\t".$timeM."\n".
			"学习：\t".$ret[question]."\n".
			"回答：\t".$ret[answer];
			
		} else {
			$this->message = "数据异常" ;
			
		}
	}
	
	private function aToBcluster() {
		$sql="select * from td_a_to_b where Parents='{$_POST[ClusterNum]}'" ;
		myEcho($sql);
		$ret2=DB::GetQueryResult($sql,false);
		$mess = "本消息来自群[{$_POST[ClusterName]}({$_POST[ClusterNum]})]\n".$_POST[Nick]."({$_POST[Sender]})".date("H:i:s",(time()+8*3600 ))."\n ".$_POST[Message];
		if(count($ret2)<=0) {
			return ;
		}
		$qq="";
		foreach($ret2 as $v) {
			if($qq=="") {
				$qq=$v[child];
			} else
				$qq=$qq.",".$v[child];
		}
		$api = new Api("SendClusterMessage");
		$api->doApi($qq, $mess);
	}
	
	private function quitCluster() {
//			$ret2 = @DB::LimitQuery('td_a_to_b',array('condition'=>array('Parents'=> "243771033")),false);
//			if(!$is_admin&&!$ret2 && $post[ClusterNum]=="243771033") {
//				 echo "目前尚未有链接~！";
//				 exit;
//			}
			
			$sql = "delete from td_a_to_b where Parents = '{$_POST[ClusterNum]}' or child='{$_POST[ClusterNum]}' ";
			$ret = @DB::LimitQuery('td_a_to_b',array('condition'=>array('Parents'=> $_POST[ClusterNum])),false);
			$qq= $ret[0][child];
			$api = new Api("SendClusterMessage");
		  	$api->doApi($qq, "{$_POST[Nick]} 已经退出该群~！会话结束~！");
		    @DB::Query($sql);
		    $this->message = "退出成功   会话结束~！";
	}
	private function __get($property_name) {
		//myEcho();
		if ($property_name == "message") {
			if (preg_match('/\[字体[^\]]*\]/is', $this-> $property_name, $m)) {
				return $this-> $property_name;
			}
			$myfont = $this->cp->getMyParamValue("font") ;
			$font =  $myfont? $myfont:$this->cp->getParamValue("CLUSTER_FONT_MESS", true);
			return ($font) . ($this-> $property_name);

		} else
			return $this-> $property_name;
	}
	
	private function  exitCluster($c) {
		$api = new  Api("ExitCluster");
		$api->doApi($c, "");
		@ DB :: Query("update td_cluster_favorable set  `is_in_cluster`=0  where ClusterNum='{$c}'");
	}
	
	private function __set($property_name, $value) {
		$this-> $property_name = $value;
	}

}
?>